package com.gae.blore.client.map;

import org.gwtopenmaps.openlayers.client.Map;
import org.gwtopenmaps.openlayers.client.MapOptions;
import org.gwtopenmaps.openlayers.client.MapWidget;
import org.gwtopenmaps.openlayers.client.Projection;

import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.Widget;

public class MapWrapperPanel extends DockPanel {

	private MapOptions defaultMapOptions;
	// private MapWidget mapWidget;
	private Map map;

	public MapWrapperPanel() {
		this.defaultMapOptions = new MapOptions();
		// In OL, the map gets PanZoom, Navigation, ArgParser, and Attribution
		// Controls
		// by default. Do removeDefaultControls to remove these.
		this.defaultMapOptions.removeDefaultControls();
		this.defaultMapOptions.setNumZoomLevels(1);
		this.defaultMapOptions.setProjection("EPSG:900913");
		
		Projection projection= new Projection("EPSG:900913");
		
		defaultMapOptions.setDisplayProjection(projection);
		initMapWidget(this.defaultMapOptions);
		
	}

	public MapWrapperPanel(MapOptions options) {
		initMapWidget(options);
	}

	private void initMapWidget(MapOptions options) {
		MapWidget mapWidget = new MapWidget("700px", "500px", defaultMapOptions);
		this.map = mapWidget.getMap();
		
		add(mapWidget, DockPanel.CENTER);
		
	}

	public Map getMap() {
		return this.map;
	}

	public void destroy() {
		this.map.destroy();

	}

	public void add(Widget w, DockLayoutConstant c) {
		super.add(w, c);
	}
}
